import mockApi from "@/api/mockApi";
import type {ApplicationRecordForm} from '@/types/req/applicationRecordForm'
import type {ApplicationRecordQueryForm} from '@/types/req/applicationRecordQueryForm'
import type {ApplicationRecord} from '@/types/resp/applicationRecord'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";

export default class applicationRecordApi {
  static applicationRecords: ApplicationRecord[] = [
    {"id":1,"enterpriseId":2,"enterpriseName":"腾讯科技","jobDescriptionId":1,"jobDescriptionName":"后端开发工程师","candidateId":1,"candidateName":"王强","status":90,"createTime":"2024-08-24 22:43:13","modifyTime":"2024-01-18 22:43:13"},
    {"id":2,"enterpriseId":3,"enterpriseName":"阿里健康","jobDescriptionId":2,"jobDescriptionName":"数据分析师","candidateId":3,"candidateName":"张伟","status":10,"createTime":"2024-06-02 22:43:13","modifyTime":"2024-11-12 22:43:13"},
    {"id":3,"enterpriseId":4,"enterpriseName":"新东方教育","jobDescriptionId":2,"jobDescriptionName":"数据分析师","candidateId":2,"candidateName":"陈静","status":30,"createTime":"2024-04-01 22:43:13","modifyTime":"2024-02-07 22:43:13"},
    {"id":4,"enterpriseId":3,"enterpriseName":"阿里健康","jobDescriptionId":2,"jobDescriptionName":"数据分析师","candidateId":3,"candidateName":"张伟","status":90,"createTime":"2024-02-29 22:43:13","modifyTime":"2024-09-07 22:43:13"},
    {"id":5,"enterpriseId":2,"enterpriseName":"腾讯科技","jobDescriptionId":4,"jobDescriptionName":"产品经理","candidateId":2,"candidateName":"陈静","status":20,"createTime":"2025-01-01 22:43:13","modifyTime":"2024-07-30 22:43:13"},
    {"id":6,"enterpriseId":4,"enterpriseName":"新东方教育","jobDescriptionId":1,"jobDescriptionName":"后端开发工程师","candidateId":1,"candidateName":"王强","status":30,"createTime":"2024-01-16 22:43:13","modifyTime":"2024-09-01 22:43:13"}
  ]

  static async save (applicationRecordForm: ApplicationRecordForm): Promise<Result<void>> {
    console.log('applicationRecordApi save params', applicationRecordForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (applicationRecordQueryForm: ApplicationRecordQueryForm): Promise<Result<Page<ApplicationRecord>>> {
    console.log('applicationRecordApi find params', applicationRecordQueryForm)
    let filteredApplicationRecords = applicationRecordApi.applicationRecords
    if (applicationRecordQueryForm.candidateId) {
      filteredApplicationRecords = applicationRecordApi.applicationRecords.filter(applicationRecord => applicationRecord.candidateId === applicationRecordQueryForm.candidateId);
    }
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(filteredApplicationRecords)
    return response.data
  }

  static async findById (id: number): Promise<Result<ApplicationRecord>> {
    console.log('applicationRecordApi findById id', id)
    let target = {}
    for (const a of applicationRecordApi.applicationRecords) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<ApplicationRecord> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('applicationRecordApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}